
/*change directory in libname statement to wherever data file is stored*/
libname everify "D:\state immigration laws\RESTATREVISION\program files for RESTAT readme";
options nocenter;
options linesize=78;

/* the following code in the data step restricts the data to Arizona, flags immigrants, non-citizens, and Hispanics, and recodes education into
the four categories used in Table 1*.  The recoded data is saved as a temporary file for the purposes of producing the trends in table 1*/
data test;
set everify.combined;
if gestfips=4;
if race=1 and hispanic=2 then racer=1;
else if race=2 and hispanic=2 then racer=2;
else if race=3 and hispanic=2 then racer=3;
else if race=4 and hispanic=2 then racer=4;
else if racer>4 and hispanic=2 then racer=5;
else if hispanic=1 then racer=6;
if sex=2 then female=1; else female=0;

if 31 le educ le 38 then educrecode=1;
else if educ=39 then educrecode=2;
else if 40 le educ le 42 then educrecode=3;
else if educ ge 43 then educrecode=4;
else educrecode=".";
if educrecode=1 then educ1=1; else educ1=0;
if educrecode=2 then educ2=1; else educ2=0;
if educrecode=3 then educ3=1; else educ3=0;
if educrecode=4 then educ4=1; else educ4=0;
if country ge 100 and citizen in (4,5) then foreign=1; else foreign=0;
if hispanic=1 then hispdummy=1; else hispdummy=0;
foreignhispanic=foreign*hispdummy;
foreigneduc1=foreign*educ1;
foreigneduc2=foreign*educ2;
foreigneduc3=foreign*educ3;
foreigneduc4=foreign*educ4;

if citizen=5 then noncitizen=1; else noncitizen=0;
nceduc1=noncitizen*educ1;
nceduc2=noncitizen*educ2;
nceduc3=noncitizen*educ3;
nceduc4=noncitizen*educ4;
hispnoncitizen=noncitizen*hispdummy;
hnceduc1=hispnoncitizen*educ1;
hnceduc2=hispnoncitizen*educ2;
hnceduc3=hispnoncitizen*educ3;
hnceduc4=hispnoncitizen*educ4;
if 15<age<46 then prime=1; else prime=0;
hispnoncitizenprime=noncitizen*prime*hispdummy;
hispnoncitizenprimee1=noncitizen*prime*hispdummy*educ1;
hispnoncitizenprimee2=noncitizen*prime*hispdummy*educ2;
hispnoncitizenprimee3=noncitizen*prime*hispdummy*educ3;
hispnoncitizenprimee4=noncitizen*prime*hispdummy*educ4;


if noncitizen=0 and hispdummy=1 and foreign=1 then hispcitizen=1;
else hispcitizen=0;
hispcitizeneduc1=hispcitizen*educ1;
hispcitizeneduc2=hispcitizen*educ2;
hispcitizeneduc3=hispcitizen*educ3;
hispcitizeneduc4=hispcitizen*educ4;

if citizen in (1,2,3) then citizenship=1;
else if citizen=4 then citizenship=2;
else if citizen=5 then citizenship=3;
if employment in (1,2) then employed=1; else employed=0;
statefip=gestfips;
run;

proc sort;
by year;
run;
 


/*the following proc means statement produces means for many different groups with unrestricted age for Arizona for 1998 through 2009.
the means for the variables noncitizen and hispnoncitizen produce the figures for the first two rows of table 1*/
proc means;
var noncitizen hispnoncitizen;
by year;
weight weight;
run;

/*the following means procedure produces mean fogure for Arizona for 1998 through 2009 for those 15 and over.  The means for hispnoncitizen,
hnceduc1, hnceduc2, hnceduc3, and hnceduc4 produce the means for rows three through seven in table 1*/

proc means;
var hispnoncitizen hnceduc1 hnceduc2 hnceduc3 hnceduc4;
by year;
weight weight;
where age ge 15;
title 'over15';
run;


/*the following means procedure produces mean fogure for Arizona for 1998 through 2009 for those 15 to 45 years of age.  The means for hispnoncitizen,
hnceduc1, hnceduc2, hnceduc3, and hnceduc4 produce the means for rows eight through twelve in table 1*/

proc means;
var hispnoncitizen hnceduc1 hnceduc2 hnceduc3 hnceduc4;
by year;
weight weight;
where age ge 15 and age le 45;
title '15 to 45';
run;


 